import $http from 'servers/http';
import { Result } from 'seats/schema/Result';
/* 坐席上下班
---------------------------------------------------------------- */
import {
  OndutyResponse,
  AttributesParam,
  FlowNodesScama,
  Flowrecord,
  CustomersDetails,
} from 'seats/schema/CheckInOut';
import { JSONObject } from 'seats/schema/common';

/** 接口-坐席上班*/
export const onDuty = (): Promise<Result<OndutyResponse>> => {
  return $http.post({
    url: '/seats/onduty',
  });
};
/** 接口-坐席下班*/
export const offDuty = (): Promise<Result<any>> => {
  return $http.post({
    url: '/seats/offduty',
  });
};

/**
 *客户资料-查询
 */
export const customersInfo = (callRecordId: string): Promise<Result<CustomersDetails>> => {
  return $http.get({
    url: `/icms/callgroupmanager/customers/info?callRecordId=${callRecordId}`,
  });
};

/**
 *客户资料-保存
 */
export const customersInfoPut = (
  callRecordId: string,
  reqAttributes: AttributesParam[],
  userIntention: number
): Promise<Result<null>> => {
  return $http.put({
    url: '/icms/callgroupmanager/customers/info',
    data: {
      callRecordId,
      reqAttributes,
      userIntention,
    },
  });
};

/**
 *查询机器人或版本的可跳转流程节点列表
 */
export const robotsSkipnodes = (robotId: number): Promise<Result<FlowNodesScama[]>> => {
  return $http.get({
    url: `/robotmanage/robots/skipnodes?robotId=${robotId}`,
  });
};
/**
 *人工介入-流程记录
 */
export const taskFlowrecord = (callRecordId: string): Promise<Result<Flowrecord[]>> => {
  return $http.get({
    url: `/seats/seatstask/tasks/flowrecord?callRecordId=${callRecordId}`,
  });
};
/**
 *人工介入-跳转到指定节点
 */
export const tasksSkip = (callId: string, node: number): Promise<Result<any>> => {
  return $http.post({
    url: `/seats/seatstask/tasks/skip`,
    data: {
      callId,
      node,
    },
  });
};
/**
 *-人工介入-挂断
 */
export const tasksHangup = (callId: string): Promise<Result<any>> => {
  return $http.post({
    url: `/seats/seatstask/tasks/hangup`,
    data: {
      callId,
    },
  });
};
/**
 *-人工介入-转回流程
 */
export const tasksReturn = (callId: string): Promise<Result<any>> => {
  return $http.post({
    url: `/seats/seatstask/tasks/return`,
    data: {
      callId,
    },
  });
};

/**
 *通话小结-保存
 */
export const callsummary = (data: JSONObject): Promise<Result<null>> => {
  return $http.put({
    url: `/seats/callrecords/callsummary/${data.callRecordId}`,
    data: data,
  });
};
